<?php
	
	if(!defined('APP')){
		die('error');
	}
	
	class Ajax extends ApiBase  {

		//构造函数
		function __construct(){
			parent::__construct();
			$this->image=new Image();
			$this->getDb();
		}
		
			
		//删除多张图片
		function delImgs(){
			$url=$_REQUEST['url'];
			echo $this->image->delete($url);
		}
		
		//加载所有图片
		function loadAllImages(){
			$arr=File::getImages('upload/');
			echo json_encode( $arr );
		}
		
		function back($title,$hm){
			echo <<<js
				<h3>{$title}</h3>
				<script>
					setTimeout(function(){
						history.go(-1)
					},{$hm})
				</script>
js;
		}
		
		function jscss(){
			echo <<<css
				<meta charset="utf-8" />
				<link rel="stylesheet" type="text/css" href="/layui/css/layui.css" />
				<script src="/layui/layui.all.js" type="text/javascript" charset="utf-8"></script>				
css;
		}
			
		//多图上传
		function duoTuUpload(){
			$imgs=$this->image->duotu_upload('files');
			$this->jscss();
			$arr=explode(';',$imgs);
			?>		
			<div class="layui-carousel" id="test1" lay-filter="test1">
			  
			  	<?php
			  		
			  		foreach($arr as $k=>$v ){
			  			
				  		echo<<<sss
				  			
					  		<div carousel-item="">
						    	<div style="text-align:center;">
						    		<img src="{$v}" style="width:99%;"/>
						    	</div>
						     </div>
					     
sss;
		  		}		  		
		    ?>
		 
			</div> 
			
			<script>
	    		layui.use(['carousel'], function(){
					var carousel = layui.carousel
				  	carousel.render({
				    	elem: '#test1'
				    	,arrow: 'always'
				  	});
				})
	    	</script>
	    	
			<?php
			$this->back('多张图片上传成功',2000);
		}
			
		
		//单图上传
		function danTuUpload(){
			
			$img =$this->image->dantu_upload('file');
			$this->jscss();
			echo <<<aaa
				<div style="padding: 20px; background-color: #F2F2F2;">
				  	<div class="layui-row layui-col-space15">				    
					    <div class="layui-col-md12">
						    <div class="layui-card">
						        <div class="layui-card-header">上传成功的图片</div>
						        <div class="layui-card-body">
						          	<img src="$img" style="width:100%;"/>
						        </div>
						    </div>
					    </div>
				  	</div>
				</div> 
aaa;
			$this->back('图片上传成功',2000);
 		
		}
		
		
		//单图上传
		function danImgUpload(){
			$img =$this->image->dantu_upload('file');
			echo $img;
		}
		
			
	    //layui 单张图片上传
	    public function imageUpload()
	    {  
	    	//获取文件
	    	$img=new Image();
	    	$src=$img->dantu_upload('image'); 
	        $changJingName = $this->db->getval('changJingName');
	        //存储图片
	        $query = "insert into " . QZ . "image(
	                    changJingName,src
	                )values(
	                    '{$changJingName}','{$src}'
	                )";
	        $this->db->exec($query);
	    	$arr=['code'=>0, 'src'=>$src];
	    	echo json_encode($arr); 
	    }
	    
	    //视频上传
	    public function vidoeUpload(){
	     
	    	//获取文件
	        $changJingName = $this->db->getval('changJingName');	   
	    	$fi=new File();
	    	
	    	/*$arr=[ 'request'=>$_REQUEST, 'files'=>$_FILES];
	    	echo json_encode($arr); 
	    	die();*/
	    	$src=$fi->getvideo('video'); 
	    	
	        $query = "insert into " . QZ . "image(
	                    changJingName,src
	                )values(
	                    '{$changJingName}','{$src}'
	                )";
	        $this->db->exec($query);
	    	$arr=['code'=>0, 'src'=>$src];
	    	echo json_encode($arr); 
	    }
		
	}
